package com.blb.search_service.controller;

import com.blb.search_service.entity.JsonResult;
import com.blb.search_service.entity.PageResult;
import com.blb.search_service.entity.Spu;
import com.blb.search_service.service.SpuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("goods")
public class SpuController {

    @Autowired
    private SpuService spuService;

    @GetMapping("/page/{page}")
    public JsonResult<PageResult<Spu>> page(@PathVariable("page") Long page,
                    @RequestParam(value = "key",required = false,defaultValue = "")String key){
        try {
            PageResult<Spu> res = spuService.page(key, page);
            return new JsonResult<>(1,res);
        }catch (Exception ex){
            ex.printStackTrace();
            return new JsonResult<>(0,null);
        }
    }
}
